<?php
 $link = mysql_connect('localhost', 'kootenay', 'nonsense');
 if (!$link) {
  die ('Not connected : ' . mysql_error());
 }
 $db_selected = mysql_select_db('kootenay', $link);

 if (!$db_selected) {
  die ('Can\'t use foo : ' . mysql_error());
 }
 
 $keywords = array();
 
$query='SELECT album_id FROM ml_albums';
$result= mysql_query($query);
while ($row = mysql_fetch_array($result) )
{
	$album_id = $row[0];
	unset ($keywords);
	$user_query='SELECT * FROM ml_album_keywords WHERE album_id = "'.$album_id.'"'; //echo $user_query;
	$user_result=mysql_query($user_query);
	while ($user_row = mysql_fetch_array($user_result, MYSQL_NUM) )
	{
		$keyword_id = $user_row[1];
		$keyword_query='SELECT * FROM ml_keywords WHERE keyword_id = "'.$keyword_id.'"'; //echo $keyword_query;
		$keyword_result=mysql_query($keyword_query);
		$keyword_row = mysql_fetch_array($keyword_result, MYSQL_NUM);
		$keywords[] = $keyword_row[1];
	}
	
	unset ($keyword_string);
	if ($keywords) foreach($keywords as $val) {$keyword_string .= $val.", "; }
	
	$keywords_string = rtrim($keyword_string, ", ");

	$update_query = 'UPDATE ml_albums SET keywords ="'. $keywords_string . '" WHERE album_id = "'.$album_id.'"';
	$update_result = mysql_query ($update_query); echo $update_query;
	if ($update_result) echo "     updated " . $album_id. "  ";
	
	echo " album: $album_id  keywords:  $keywords_string"; echo "<br>";
	
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
